home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / freemacs.arc / Z100.ASM < prev   
Assembly Source File  |  1988-03-17  |  12KB  |  601 lines

  1. ;History:52,1
  2.  
  3.     page    ,132
  4.  
  5. comment /
  6.  
  7.     Porting EMACS and Percival to MS-DOS computers other than the Z-100:
  8.  
  9. This entire file (Z-100.ASM) needs to be re-written, since it contains
  10. all the Z-100 dependencies.  The following conventions must be maintained:
  11.   1) Never leave this module with DF=1.
  12.   2) Never destroy ES.
  13.   3) Never MOV AX,DATA, always use the copy in the appropriate segment register.
  14.   4) Return NC if a routine succeeds, or fulfills its goals.
  15.  
  16. /
  17.     .xlist
  18.  
  19.     include    memory.def
  20.  
  21.  
  22. ;the only bios call is used by check_for_key
  23. bios_seg    segment at 40h
  24.     org    27*3
  25. bios_confunc    label    far
  26. bios_seg    ends
  27.  
  28.  
  29. data    segment    byte public
  30.  
  31.     public    max_screen_line
  32. max_screen_line    db    22    ;number of last text row on screen.
  33.  
  34. fontptr        dd    6fh
  35.  
  36. ;the following font pointers point to a font containing the 96 printable
  37. ;  characters, with the exception of the first which also contains graphics.
  38. ;  The first font is numbered zero, and has all the Zedit funnies.  The
  39. ;  second  font uses the first_font, but does inverse video for the high bit
  40. ;  characters.  The third font and on use the normal control character font to
  41. ;  print controls.  The last font is the internal font, and is used to print
  42. ;  control chars, etc.
  43. first_font    dw    ?,?        ;fonts zero and one.
  44.  
  45. controls_ptr    label    word        ;font eight.
  46.     dw    controls,?
  47.  
  48. controls    label    byte
  49.     include    control.asm
  50.  
  51.  
  52.     public    scan_lines_per_char
  53. scan_lines_per_char    db    9    ;used to convert pixel position into character position.
  54.  
  55.  
  56. shifted    equ    40h
  57. key_names    label    byte
  58.     db    ',','Comma',0
  59.     db    '(','LPar',0
  60.     db    ')','RPar',0
  61.     db    7fh,'Delete',0
  62.     db    0a3h+shifted,'D Chr',0
  63.     db    0a3h,'I Chr',0
  64.     db    0a4h+shifted,'Del Line',0
  65.     db    0a4h,'Ins Line',0
  66.     db    -1,'Timeout',0
  67.     db    -2,'Left Down',0        ;mouse button key names.
  68.     db    -3,'Right Down',0
  69.     db    -4,'Left Up',0
  70.     db    -5,'Right Up',0
  71.     db    -6,'Middle Down',0
  72.   if 0
  73.     db    -7,'Middle Up',0
  74.   endif
  75.     db    0
  76.  
  77. key_shifted    label    byte
  78.     db    08Dh,'Enter',0
  79.     db    095h,'Help',0
  80.     db    096h,'F0',0
  81.     db    097h,'F1',0
  82.     db    098h,'F2',0
  83.     db    099h,'F3',0
  84.     db    09Ah,'F4',0
  85.     db    09Bh,'F5',0
  86.     db    09Ch,'F6',0
  87.     db    09Dh,'F7',0
  88.     db    09Eh,'F8',0
  89.     db    09Fh,'F9',0
  90.     db    0A0h,'F10',0
  91.     db    0A1h,'F11',0
  92.     db    0A2h,'F12',0
  93.     db    0A5h,'Up Arrow',0
  94.     db    0A6h,'Down Arrow',0
  95.     db    0A7h,'Right Arrow',0
  96.     db    0A8h,'Left Arrow',0
  97.     db    0A9h,'Home',0
  98.     db    0AAh,'Break',0
  99.     db    0ADh,'KP-',0
  100.     db    0AEh,'KP.',0
  101.     db    0B0h,'KP0',0
  102.     db    0B1h,'KP1',0
  103.     db    0B2h,'KP2',0
  104.     db    0B3h,'KP3',0
  105.     db    0B4h,'KP4',0
  106.     db    0B5h,'KP5',0
  107.     db    0B6h,'KP6',0
  108.     db    0B7h,'KP7',0
  109.     db    0B8h,'KP8',0
  110.     db    0B9h,'KP9',0
  111.     db    0,'Unknown',0
  112.  
  113.  
  114. key_buffer    label    byte
  115.     db    12 dup(?)
  116.  
  117.  
  118.     extrn    inversing: word
  119.  
  120. color_xlat    db    0, 1, 4, 5, 2, 3, 6, 7
  121.  
  122. ;a character must be chosen which causes the idling string to be reloaded.
  123. ;  this one is shift-help.
  124.     public    breakchar
  125. breakchar    dw    0d5h
  126.  
  127. data    ends
  128.  
  129.  
  130. bios_seg    segment at 40h
  131.     org    9h
  132. bios_conout    label    far
  133. bios_seg    ends
  134.  
  135.  
  136. code    segment    byte public
  137.     assume    cs:code, ds:data, es:nothing
  138. ;all of the code in this segment is called with the above assumes.
  139.  
  140.  
  141. printchar:
  142.     call    bios_conout
  143.     ret
  144.  
  145.  
  146.     public    init_entry
  147. init_entry:
  148. ;called when entering.  May destroy any but seg-regs.
  149.     push    es
  150.     xor    ax,ax
  151.     mov    es,ax
  152.     mov    ax,es:3feh    ;the monitor segment
  153.     mov    word ptr fontptr+2,ax
  154.     les    si,fontptr
  155.     mov    ax,es:[si]
  156.     mov    first_font,ax
  157.     mov    bx,es:[si+2]
  158.     mov    first_font+2,bx
  159.     pop    es
  160.     mov    controls_ptr+2,ds
  161.     mov    al,'y'            ;disable key expansion
  162.     call    printesc
  163.     mov    al,'?'
  164.     call    printchar
  165.     mov    al,'y'
  166.     call    printesc
  167.     mov    al,'1'
  168.     call    printchar
  169.     mov    al,'x'
  170.     call    printesc
  171.     mov    al,'1'
  172.     call    printchar
  173.     mov    dx,0*256 + 49        ;try to put the cursor way down low.
  174.     call    position_cursor
  175.     push    ds            ;see if it got there.
  176.     xor    ax,ax
  177.     mov    ds,ax
  178.     mov    ds,ds:[3feh]
  179.     mov    al,ds:[292h]
  180.     pop    ds
  181.     cmp    al,49            ;go if it didn't
  182.     jne    init_entry_1
  183.     mov    max_screen_line,47    ;it did - remember the last scrollable line.
  184. init_entry_1:
  185.     ret
  186.  
  187.  
  188.     public    uninit_exit
  189. uninit_exit:
  190. ;called when exiting.  May destroy any but seg-regs.
  191.     call    restore_font
  192.     mov    al,'x'            ;enable key expansion
  193.     call    printesc
  194.     mov    al,'?'
  195.     call    printchar
  196.     mov    al,'y'            ;disable the 25th line.
  197.     call    printesc
  198.     mov    al,'1'
  199.     call    printchar
  200.     mov    dh,0            ;put the cursor on the last scrollable line.
  201.     mov    dl,max_screen_line
  202.     inc    dl
  203.     call    position_cursor
  204.     ret
  205.  
  206.  
  207. restore_font:
  208.     push    es
  209.     les    si,fontptr
  210.     mov    ax,first_font
  211.     mov    es:[si],ax
  212.     mov    ax,first_font+2
  213.     mov    es:[si+2],ax
  214.     pop    es
  215.     ret
  216.  
  217.  
  218.     public    check_for_key
  219. check_for_key:
  220. ;return zr if no key is waiting.
  221. ;return nz,ax=key if a key is waiting, but don't input the key yet.
  222.     push    bx        ; Save regs
  223.     push    di
  224.     push    si
  225.     push    dx
  226.     push    ax
  227.     mov    ah,4        ; get look function
  228.     call    bios_confunc     ; get copy of first char in queue, empty?
  229.     mov    bl,0        ; assume queue empty, was it ?
  230.     jc    check_for_key_1    ;    yes, skip
  231.     mov    bl,al        ;    no, save char
  232. check_for_key_1:
  233.     mov    al,0ffh        ; get -1
  234.     adc    al,0        ; set 'z' flag appropriately
  235.     pop    ax        ; recover ax
  236.     mov    al,bl        ; get char
  237.     pop    dx        ; restore regs
  238.     pop    si
  239.     pop    di
  240.     pop    bx
  241.     mov    ah,0
  242.     ret
  243.  
  244.  
  245.     public    get_key_value
  246. get_key_value:
  247.     mov    ah,7
  248.     int    21h
  249.     mov    ah,0
  250.     ret
  251.  
  252.  
  253.     public    decode_key
  254. decode_key:
  255. ;enter with al=key value.
  256. ;exit with si,cx -> the key's name in ASCII.
  257.     mov    di,offset key_buffer
  258.     mov    ah,al
  259.     mov    si,offset key_names
  260.     call    decode_search        ;search for the literal names.
  261.     jne    decode_key_1
  262.     mov    si,offset key_shifted    ;search for the unshifted versions.
  263.     call    decode_search
  264.     jne    decode_key_1
  265.     mov    al,'s'
  266.     stosb
  267.     push    ax            ;save the key's value.
  268.     and    ah,not shifted        ;search for the shifted versions.
  269.     mov    si,offset key_shifted    ;search for the unshifted versions.
  270.     call    decode_search
  271.     pop    ax
  272.     jne    decode_key_1
  273.     dec    di            ;remove the 's'.
  274.     mov    al,ah
  275.     cmp    al,' '            ;control char?
  276.     jb    decode_key_3        ;yes.
  277.     stosb                ;no - just return the char.
  278.     jmp    decode_key_2
  279. decode_key_3:
  280.     mov    word ptr [di],'C' + '-'*256
  281.     add    di,2
  282.     add    al,'@'
  283.     stosb
  284.     jmp    decode_key_2
  285. decode_key_1:
  286.     lodsb                ;copy to the next null.
  287.     stosb
  288.     or    al,al
  289.     jne    decode_key_1
  290.     dec    di            ;don't include the null.
  291. decode_key_2:
  292.     mov    si,offset key_buffer
  293.     mov    cx,di
  294.     sub    cx,si
  295.     ret
  296.  
  297.  
  298. decode_search:
  299. ;enter with ah=key to search for, si->table.
  300. ;exit with al=key, nz if found, al=0, zr if not found.
  301.     lodsb
  302.     or    al,al            ;end of table?
  303.     je    decode_search_2        ;yes - try shifted values.
  304.     cmp    al,ah            ;is this the key?
  305.     je    decode_search_2        ;yes.
  306. decode_search_1:
  307.     lodsb                ;skip to the next null.
  308.     or    al,al
  309.     jne    decode_search_1
  310.     jmp    decode_search
  311. decode_search_2:
  312.     or    al,al
  313.     ret
  314.  
  315.  
  316. printesc:
  317. ;print an escape followed by the char in al.
  318.     push    ax
  319.     mov    al,ESC
  320.     call    printchar
  321.     pop    ax
  322.     call    printchar
  323.     ret
  324.  
  325.  
  326.     public    ring_the_bell
  327. ring_the_bell:
  328.     mov    al,'G'-40h
  329.     call    printchar
  330.     ret
  331.  
  332. code    ends
  333.  
  334. code    segment    byte public
  335.     assume    cs:code, ds:nothing, es:data
  336. ;all of the code in this segment is called with the above assumes.
  337.  
  338.     public    position_cursor
  339. position_cursor:
  340. ;enter with dh=col (0...80), dl=row (0..max_screen_line)
  341. ;exit with cursor set to that position.
  342.     mov    al,'Y'
  343.     call    printesc
  344.     mov    al,dl
  345.     add    al,' '
  346.     call    printchar
  347.     mov    al,dh
  348.     add    al,' '
  349.     call    printchar
  350.     ret
  351.  
  352.  
  353.     public    solid_cursor
  354. solid_cursor:
  355.     mov    al,'x'
  356.     call    printesc
  357.     mov    al,';'
  358.     call    printchar
  359.     ret
  360.  
  361.  
  362.     public    blink_cursor
  363. blink_cursor:
  364.     mov    al,'y'
  365.     call    printesc
  366.     mov    al,';'
  367.     call    printchar
  368.     ret
  369.  
  370.  
  371.     public    block_cursor
  372. block_cursor:
  373.     mov    al,'x'
  374.     call    printesc
  375.     mov    al,'4'
  376.     call    printchar
  377.     ret
  378.  
  379.     public    underscore_cursor
  380. underscore_cursor:
  381.     mov    al,'y'
  382.     call    printesc
  383.     mov    al,'4'
  384.     call    printchar
  385.     ret
  386.  
  387.  
  388.     public    set_screen_color
  389. set_screen_color:
  390. ;enter with al=fore color, ah=back color
  391.     push    ax
  392.     mov    al,'m'
  393.     call    printesc
  394.     pop    ax
  395.     mov    bx,offset color_xlat
  396.     xlat
  397.     add    al,'0'            ;print the fore color number.
  398.     call    printchar
  399.     mov    al,ah            ;print the back color number.
  400.     xlat
  401.     add    al,'0'
  402.     call    printchar
  403.     ret
  404.  
  405.  
  406.     public    move_line
  407. move_line:
  408. ;enter with dl=source row, al=destination row.
  409.     push    ax
  410.     push    bx
  411.     push    cx
  412.     push    dx
  413.     push    si
  414.     push    di
  415.     push    bp
  416.     push    es
  417.     push    ds
  418. ;start pushing mtr_mdl parameters
  419.     push    dx            ;source line.
  420.     push    ax            ;destination line.
  421.     xor    ax,ax
  422.     mov    ds,ax
  423.     mov    ds,ds:3feh        ;the monitor segment
  424.     call    dword ptr ds:[77h]    ;mtr_mdl
  425.     pop    ds
  426.     pop    es
  427.     pop    bp
  428.     pop    di
  429.     pop    si
  430.     pop    dx
  431.     pop    cx
  432.     pop    bx
  433.     pop    ax
  434.     ret
  435.  
  436.  
  437.     public    clear_to_eol
  438. clear_to_eol:
  439. ;enter with dl=current row, dh=current column.
  440.     push    bx
  441.     mov    bl,80
  442.     call    clear_count
  443.     pop    bx
  444.     ret
  445.  
  446.  
  447.     public    clear_count
  448. clear_count:
  449. ;enter with dl=current row, dh=current column, bl=column to clear to.
  450.     cmp    dh,bl        ;already past it?
  451.     jae    clear_count_1    ;yes.
  452.     push    ax
  453.     push    bx
  454.     push    cx
  455.     push    dx
  456.     push    si
  457.     push    di
  458.     push    bp
  459.     push    es
  460.     push    ds
  461. ;start pushing edc parameters.
  462.     push    dx            ;push row,
  463.     xchg    dl,dh
  464.     push    dx            ;push col.
  465.     sub    bl,dl
  466.     push    bx            ;push count of columns to clear.
  467.     xor    ax,ax
  468.     mov    ds,ax
  469.     mov    ds,ds:3feh        ;the monitor segment
  470.     call    dword ptr ds:[67h]    ;mtr_edl
  471.     pop    ds
  472.     pop    es
  473.     pop    bp
  474.     pop    di
  475.     pop    si            ;restore saved registers.
  476.     pop    dx
  477.     pop    cx
  478.     pop    bx
  479.     pop    ax
  480. clear_count_1:
  481.     ret
  482.  
  483.  
  484.     public    xychrout
  485. xychrout:
  486. ;enter with dh=col, dl=row, al=character to print, ah=font to print it in.
  487.     push    ax            ;save everything that we might need.
  488.     push    bx
  489.     push    cx
  490.     push    dx
  491.     push    di
  492.     push    si
  493.     push    es
  494.     push    ds
  495.     cmp    dh,80            ;past the right margin?
  496.     jae    xychrout_3        ;yes - don't print.
  497.     mov    si,offset first_font
  498.     cmp    ah,0            ;font zero?
  499.     jne    xychrout_5        ;no - print specially.
  500.     mov    bx,0            ;assume no inverse video
  501.     cmp    al,80h-'^'+7fh
  502.     jb    xychrout_1        ;print all normal chars normally.
  503.     jmp    short xychrout_0
  504. xychrout_5:
  505.     mov    si,offset controls_ptr
  506.     xor    bx,bx            ;assume no inverse video.
  507.     or    al,al            ;high bit set?
  508.     jns    xychrout_1        ;no - no inverse video.
  509. xychrout_0:
  510.     not    bx
  511.     and    al,7fh
  512. xychrout_1:
  513.     xor    bx,inversing        ;set the inverse video flag.
  514.     cmp    al,' '            ;print controls specially.
  515.     jb    xychrout_2
  516.     cmp    al,7fh            ;print delete specially.
  517.     je    xychrout_4
  518.     sub    al,' '
  519.     jmp    short xychrout_6
  520. xychrout_4:
  521.     sub    al,7fh-2fh        ;convert del to proper index in control font.
  522. xychrout_2:
  523.     mov    si,offset controls_ptr
  524. xychrout_6:
  525.     mov    cx,es            ;ensure that ds:si ->font pointer.
  526.     mov    ds,cx
  527.     les    di,fontptr
  528.     movsw
  529.     movsw
  530.     push    ds
  531. ;push four words as parameters to mtr_dfc
  532.     xchg    dh,dl
  533.     push    dx            ;push col first
  534.     xchg    dh,dl
  535.     push    dx            ;push row next.
  536.     push    ax            ;push font index.
  537.     push    bx            ;push inverse video flag.
  538.     xor    ax,ax
  539.     mov    ds,ax
  540.     mov    ds,ds:3feh        ;the monitor segment
  541.     call    dword ptr ds:[5fh]    ;mtr_dfc
  542.     pop    ds
  543.     call    restore_font
  544. xychrout_3:
  545.     pop    ds
  546.     pop    es
  547.     pop    si
  548.     pop    di
  549.     pop    dx
  550.     pop    cx
  551.     pop    bx
  552.     pop    ax
  553.     ret
  554.  
  555.  
  556.     public    hardware_roll_down
  557. hardware_roll_down:
  558. ;exit: if this machine is capable of hardware roll, do it and exit with cy=0,
  559. ;  otherwise, exit with cy=1.  The hardware roll must leave the last line
  560. ;  on the screen as the last line.
  561. ;preserve bx.
  562.     push    dx
  563.     mov    al,max_screen_line    ;move the lower status line up.
  564.     mov    dl,al
  565.     inc    dl
  566.     call    move_line        ;dl=source, al=dest.
  567.     pop    dx
  568.     mov    al,'H'            ;home up.
  569.     call    printesc
  570.     mov    al,'I'            ;reverse index.
  571.     call    printesc
  572.     clc
  573.     ret
  574.  
  575.  
  576.     public    hardware_roll_up
  577. hardware_roll_up:
  578. ;exit: if this machine is capable of hardware roll, do it and exit with cy=0,
  579. ;  otherwise, exit with cy=1.  The hardware roll must leave the last line
  580. ;  on the screen as the last line.
  581. ;preserve bx.
  582.     push    dx
  583.     mov    dl,max_screen_line
  584.     inc    dl
  585.     mov    dh,0
  586.     call    position_cursor
  587.     mov    al,LF            ;roll the screen up.
  588.     call    printchar
  589.     mov    al,max_screen_line    ;move the lower status line up.
  590.     mov    dl,al
  591.     dec    dl
  592.     call    move_line        ;dl=source, al=dest.
  593.     pop    dx
  594.     clc
  595.     ret
  596.  
  597.  
  598. code    ends
  599.  
  600.     end
  601.